﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.ComponentModel.DataAnnotations;

namespace Organizer.Model.Movie.IMDb
{
    public class Person
    {
        protected Person() { }

        [Required]
        public int PersonId { get; set; }

        [Required]
        public string Name { get; set; }

        [Required]
        private byte[] _picture { get; set; }
        [NotMapped]
        public virtual Image Picture
        {
            get
            {
                using (var stream = new MemoryStream(_picture))
                {
                    return System.Drawing.Image.FromStream(stream);
                }
            }
            set
            {
                MemoryStream stream = new MemoryStream();
                Picture.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                _picture = stream.ToArray();
            }
        }

        [Required]
        public virtual List<CharacterPerson> Characters { get; set; }
    }
}
